<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Floodlight OpenFlow Controller - Links</title>

    <!-- Bootstrap Core CSS -->
    <link href="../bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link href="../bower_components/metisMenu/dist/metisMenu.min.css" rel="stylesheet">

    <!-- DataTables CSS -->
    <link href="../bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css"
          rel="stylesheet">

    <!-- DataTables Responsive CSS -->
    <link href="../bower_components/datatables-responsive/css/dataTables.responsive.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="../dist/css/sb-admin-2.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="../bower_components/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>
<body>

<div id="wrapper">

    <!-- Navigation -->
    <nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="index.html" id="home-button-title">Floodlight OpenFlow Controller </a>
        </div>
        <!-- /.navbar-header -->
        <!-- /.navbar-top-links -->
        <div class="navbar-default sidebar" role="navigation">
            <div class="sidebar-nav navbar-collapse">
                <nav id="navMenu"></nav>
            </div>
            <!-- /.sidebar-collapse -->
        </div>
        <!-- /.navbar-static-side -->
    </nav>

    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h3 class="page-header">Links</h3>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-primary">
                    <div class="panel-heading">
                        Internal Links
                    </div>
                    <!-- /.panel-heading -->
                    <div class="panel-body">
                        <div class="dataTable_wrapper">
                            <table class="table table-striped table-bordered table-hover" id="tableInternalLinks" width="100%">
                                <thead>
                                <tr>
                                    <th>Direction</th>
                                    <th>Source Port</th>
                                    <th>Source Switch</th>
                                    <th>Destination Port</th>
                                    <th>Destination Switch</th>
                                    <!--<th>Latency (ms)</th>-->
                                    <th>Type</th>
                                </tr>
                                </thead>
                                <tbody></tbody>
                            </table>
                        </div>
                        <!-- /.table-responsive -->
                    </div>
                    <!-- /.panel-body -->
                </div>
                <!-- /.panel -->

            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
        <!-- /.row -->
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-primary">
                    <div class="panel-heading">
                        External Links
                    </div>
                    <!-- /.panel-heading -->
                    <div class="panel-body">
                        <div class="dataTable_wrapper">
                            <table class="table table-striped table-bordered table-hover" id="tableExternalLinks" width="100%">
                                <thead>
                                <tr>
                                    <th>Direction</th>
                                    <th>Source Port</th>
                                    <th>Source Switch</th>
                                    <th>Destination Port</th>
                                    <th>Destination Switch</th>
                                    <!--<th>Latency (ms)</th>-->
                                    <th>Type</th>
                                </tr>
                                </thead>
                                <tbody></tbody>
                            </table>
                        </div>
                        <!-- /.table-responsive -->
                    </div>
                    <!-- /.panel-body -->
                </div>
                <!-- /.panel -->

            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
    </div>
    <!-- /#page-wrapper -->

    <div id="login-modal-include"></div>

</div>
<!-- /#wrapper -->

<!-- jQuery -->
<script src="../bower_components/jquery/dist/jquery.min.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="../bower_components/bootstrap/dist/js/bootstrap.min.js"></script>

<!-- Metis Menu Plugin JavaScript -->
<script src="../bower_components/metisMenu/dist/metisMenu.min.js"></script>

<!-- DataTables JavaScript -->
<script src="../bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
<script src="../bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>

<!-- Custom Theme JavaScript -->
<script src="../dist/js/sb-admin-2.js"></script>
<script src="../js/jquery.cookie.js"></script>
<!-- Page-Level Demo Scripts - Tables - Use for reference -->
<script src="../js/querystringparser.js"></script>

<!-- Custom scripts to load in HTML -->
<script src="../js/navbar.js"></script>
<script>
    $(function(){
        $("#login-modal-include").load("loginmodal.html");
    });
</script>

<script>
    /*
     * These cookies are set on the login page at login.html.
     * They are simply the IP address of your controller and the REST api port.
     * */
    var ipaddress = $.cookie('cip');
    if (ipaddress == null || ipaddress == "") window.location.href = "login.html";
    var restport = $.cookie('cport');
    if (restport == null || restport == "") window.location.href = "login.html";

    $(document).ready(function () {
        loadInternalLinks();
        loadExternalLinks();

        startRefresh();
    });

    /*
     * Refreshes all of the values on the page every fifteen seconds.
     * */
    function startRefresh() {
        setTimeout(startRefresh, 15000);

        internalLinkTable.ajax.reload();
        externalLinkTable.ajax.reload();
    }

    /*
    * This function loads all the internal links that the controller sees.
    * An internal link is defined as a link that LLDP can travel across.
    **/
    function loadInternalLinks() {
        internalLinkTable = $('#tableInternalLinks').DataTable({
            responsive: true,
            searching: false,
            lengthChange: false,
            scrollX: true,
            paging: false,
            order: [[ 2, 'asc' ], [ 4, 'asc' ]],
            ajax      : {
                url    : "http://" + ipaddress + ":" + restport + "/wm/topology/links/json",
                dataSrc: ''
            },
            columns   : [
                {data: 'direction'},
                {data: 'src-port'},
                {data: 'src-switch'},
                {data: 'dst-port'},
                {data: 'dst-switch'},
//                {data: 'latency'},
                {data: 'type'}

            ]
        });

        $.ajax({
            url    : "http://" + ipaddress + ":" + restport + "/wm/topology/links/json",
            success: function (links) {
                console.log(links);
            }
        });
    }

    /*
     * This function loads all the external links that the controller sees.
     * An internal link is defined as a link that LLDP cannot travel across, only BDDP.
     **/
    function loadExternalLinks() {
        externalLinkTable = $('#tableExternalLinks').DataTable({
            responsive: true,
            searching: false,
            lengthChange: false,
            scrollX: true,
            paging: false,
            order: [[ 2, 'asc' ], [ 4, 'asc' ]],
            ajax      : {
                url    : "http://" + ipaddress + ":" + restport + "/wm/topology/external-links/json",
                dataSrc: ''
            },
            columns   : [
                {data: 'direction'},
                {data: 'src-port'},
                {data: 'src-switch'},
                {data: 'dst-port'},
                {data: 'dst-switch'},
//                {data: 'latency'},
                {data: 'type'}

            ]
        });

        $.ajax({
            url    : "http://" + ipaddress + ":" + restport + "/wm/topology/external-links/json",
            success: function (links) {
                console.log(links);
            }
        });
    }

</script>

</body>
</html>